import cv2
import numpy as np


image_path = "./dataset/cat.111.jpg"
image_size = 200


def image_trans(image_path, image_size = 100):
    img = cv2.imread(image_path)
    if img.shape[1] < img.shape[0]:
        w = image_size
        h = int(image_size * img.shape[0] / img.shape[1])
    else:
        h = image_size
        w = int(image_size * img.shape[1] / img.shape[0])
    img = cv2.resize(img, (w, h))
    # 图片裁剪：裁剪坐标为[y0:y1, x0:x1]
    x0 = int((w - image_size) / 2)
    y0 = int((h - image_size) / 2)
    x1 = int((w + image_size) / 2)
    y1 = int((h + image_size) / 2)
    img = img[y0:y1, x0:x1]
    img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    img = cv2.equalizeHist(img)
    img = gamma_trans(img, 0.8)
    # HOG描述参数
    win_size = (100, 100)
    block_size = (50, 50)
    block_stride = (10, 10)
    cell_size = (5, 5)
    nbins = 5
    hog = cv2.HOGDescriptor(win_size, block_size, block_stride, cell_size, nbins)
    hog_ndarray = hog.compute(img)
    return hog_ndarray

def gamma_trans(img, gamma):
    gamma_table = [np.power(x / 255.0, gamma) * 255.0 for x in range(256)]
    gamma_table = np.round(np.array(gamma_table)).astype(np.uint8)
    return cv2.LUT(img, gamma_table)






if __name__ == "__main__":

    res = image_trans(image_path)



